/**
 * 验证是否登陆的中间件
 */
//  export default function ({ app, store, redirect }) {
//   // If the user is not authenticated
//   console.log('验证是否登陆', app.$cookies.get('userInfo'))
//   const userInfo = app.$cookies.get('userInfo')
//   if (!userInfo?.ak) {
//     redirect('/home')
//     store.commit("user/SET_LOGIN", true);
//   }
// }

import utils from '@/utils/utils'

export default function ({route, req, res, redirect, store}) {
  let isClient = process.client;
  let isServer = process.server;
  let redirectURL = '/home';
  var token, path
 //在服务端
  if (isServer) {
    let cookies = utils.getcookiesInServer(req)
    path = req.originalUrl;
    token = cookies.token ? cookies.token : ''
    // console.log('token', token)
  }
 //在客户端判读是否需要登陆
  if (isClient) {
    token = utils.getcookiesInClient('token')
    path = route.path;
  }
  // console.log(token)
  if (path) {
    redirectURL = '/home?ref=' + encodeURIComponent(path)
  }
 //需要进行权限判断的页面开头
  if (!token) {
    // console.log('去掉ak')
    redirect(redirect)
  }
}